package util;

import java.awt.Point;

public class ResourceManager {

	private static ResourceManager manager;

	private Point[] points;

	private Point[] nearestPointPair;

	private long timeConsumed;

	private boolean resultCalculated;

	private ResourceManager() {
	}

	public static ResourceManager getResourceManager() {

		if (manager == null) {
			manager = new ResourceManager();
		}

		return manager;
	}

	public Point[] getPoints() {
		if (points == null) {
			points = new Point[0];
		}
		return points;
	}

	public void setPoints(Point[] points) {
		this.points = points;
		this.setResultCalculated(false);
	}

	public static int calcCanvasRange(int quantity) {
		return Math.max(1000, quantity / 20);
	}

	public Point[] getNearestPointPair() {
		return nearestPointPair;
	}

	public void setNearestPointPair(Point[] nearestPointPair) {
		this.nearestPointPair = nearestPointPair;
	}

	public long getTimeConsumed() {
		return timeConsumed;
	}

	public void setTimeConsumed(long timeConsumed) {
		this.timeConsumed = timeConsumed;
	}

	public boolean isResultCalculated() {
		return resultCalculated;
	}

	public void setResultCalculated(boolean resultCalculated) {
		this.resultCalculated = resultCalculated;
	}

	public double getNearestDistance(){
		if(nearestPointPair == null || nearestPointPair[0] == null||nearestPointPair[1] == null){
			return 0;
		}
		double x1 = nearestPointPair[0].x;
		double y1 = nearestPointPair[0].y;
		double x2 = nearestPointPair[1].x;
		double y2 = nearestPointPair[1].y;
		return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
	}
}
